<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>商之联后台管理系统</title>
  <meta name="description" content="商之联后台管理系统">
  <meta name="keywords" content="form">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="{:C('SHOP_HOME_IMG')}favicon.png">
  <link rel="apple-touch-icon-precomposed" href="{:C('SHOP_HOME_IMG')}app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="{:C('SHOP_HOME_CSS')}amazeui.min.css"/>
  <link rel="stylesheet" href="{:C('SHOP_HOME_CSS')}admin.css">
  <link href="{:C('SHOP_HOME_JS')}themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->
<!-- header start-->

<include file="Public:header"/>

<!-- header end-->

<div class="am-cf admin-main">
<!-- sidebar start -->
   <include file="Public:menu"/>
  <!-- sidebar end -->

<!-- content start -->
<div class="admin-content">
 
  <div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">表单</strong> / <small>form</small></div>
  </div>
  
  <div class="am-tabs am-margin" data-am-tabs >
    <ul class="am-tabs-nav am-nav am-nav-tabs">
      <li class="am-active"><a href="#tab1">基本信息</a></li>
      <li><a href="#tab2" >商品详情</a></li>
    </ul>

    <div class="am-tabs-bd">
    <!-- 商品基本信息-->
      <div class="am-tab-panel am-fade am-in am-active" id="tab1">
        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">商品类目</div>
          <div class="am-u-sm-10">
            <select name='itemtype' onchange="reload(this.options[this.options.selectedIndex].value)" disabled>
            <option value=0>请选择</option>
            <foreach name="typearr" item="types" key="key">
            
              <option value="{$key}" <?php  if($iteminfo['typeid']==$key) echo 'selected=1'; ?> > 
              <?php  echo str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',$types['level']);?> {$types['typename']}
              </option>
              </foreach>
            </select>
          </div>
        </div>
  		
  		<div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">商品名称</div>
          <div class="am-u-sm-10">
            <div class="am-btn-group" data-am-button>  
                <input type="text" name="itemname" value="{$iteminfo['itemname']}">
            </div>
          </div>
        </div>
		
		<div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">商品编号</div>
          <div class="am-u-sm-10">
            <div class="am-btn-group" data-am-button>  
                <input type="text" name="bn" value="{$iteminfo['bn']}">
            </div>
          </div>
        </div>
		<!--属性start-->
		<foreach name="typeproperty" item="propers" key="key" > 
			<div  class="am-g am-margin-top">
				<div class="am-u-sm-2 am-text-right">
					{$propers['propertyname']}
				</div>
					<div class="am-u-sm-10">
						<select name="proper[{$key}]">
						<option>请选择</option>
						<foreach name="propers.select" item="value" key="k">
							
							<option value="{$k}"
					 <if condition="$value['selected'] eq true "> selected=1</if>  >{$value['propertyvalue']}</option>
						</foreach>
						</select>
					</div>		
			</div>
	    </foreach>
  		<if condition="$brands neq '' ">
         <div  class="am-g am-margin-top">
				<div class="am-u-sm-2 am-text-right">	
				品牌
				</div>
					<div class="am-u-sm-10">
						<select name="brand">
						<option>请选择</option>
						<foreach name="brands" item="brand" key="key"> 
							<option value="{$key}"  <if condition="$iteminfo['brandid'] eq $key"> selected=1</if>  >{$brand}</option>
				        </foreach>
						</select>
					</div>		
			</div>
	    </if>
		<!-- 属性end-->
        
        <!--开启规格start-->
        
        	<div class="am-g am-margin-top">
        		
        		<div class="am-u-sm-2 am-text-right">规格</div>	
        		 <button class="am-btn am-btn-primary am-btn-xs" onclick=openspec(this)> 开启规格</button>	
        	</div>
			<!-- 选择规格start-->
			<div class='speccontain'>
			 <hr/>
			<foreach name="specs" item="spec" key="key">
        	<div class='am-g am-margin-top'>
        		<div class='am-u-sm-2 am-text-right specname'>{$spec.name}</div>
        		<div class='am-u-sm-10 spec_{$spec.specid}'>
					<foreach name="spec.specval" item="value" >
        			<span>
        		    <input type='checkbox' name="spec[{$value.specid}][{$value.specvalid}]" value="{$value.name}" class="{$value.specvalid}" <if condition="$value['checked'] eq true">checked=1 </if> >
        			<label for="{$value.name}" >{$value.name} </label></span>
        			</foreach>
        		</div>
        	</div>
			</foreach>
			<!--选择规格end -->
			<!--添加货品-->
				<div class='am-g am-margin-top'>
					<div class='am-u-sm-12'>
						<table class="am-table am-table-bordered am-table-striped am-table-compact" id='spectable'>
				    <thead>
				        <tr>
				            <th>操作</th>
				        	<foreach name="specs" item='value' key="key">
				            <th>{$value.name}</th>
				            </foreach>
				            <th>价格</th>
				            <th>库存</th>
				            
				        </tr>
				    </thead>
				    <foreach name="products" item="product" key='k'>
				    	<tr>
				    	<td>操作</td>
				    	<foreach name='specs' item='value' key='key'>
				    	<td> <select name="prospec[{$key}][key_{$k}]"> 
						<foreach name="value.specval" item='v'>
						<if condition="$v['checked'] eq true" >
						<option  value="{$v['specvalid']}"
						<if condition="$product['specs'][$v['specid']] eq $v['specvalid']">selected=1 </if> >
							{$v['name']}
							</option>
						 </if>
						</foreach>
				    	</select> </td>
				    	</foreach>
				    	<td> <input name="pprice[key_{$k}]" value="{$product['price']}"> </td>
				    	<td><input  name="pinventory[key_{$k}]" value="{$product['inventory']}"></td>
				    	</tr>
				    </foreach>
				    <tbody> 
				    </tbody>
				    </table>
					</div>
					
				</div>
			<!--添加货品 -->
				<hr/>
		</div>
        <!--开启规格end-->
	

        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">商品价格</div>
          <div class="am-u-sm-10">
            <div class="am-btn-group" data-am-button>  
                <input type="text" name="price"  value="{$iteminfo['price']}">(开启规格后，价格必须在货品价格之间)
            </div>
          </div>
        </div>

        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">市场价格</div>
          <div class="am-u-sm-10">
            <div class="am-btn-group" data-am-button>  
                <input type="text" name="mkprice" value="{$iteminfo['mkprice']}" >
            </div>
          </div>
        </div>

         <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">商品库存</div>
          <div class="am-u-sm-10">
            <div class="am-btn-group" data-am-button>  
                <input type="text" name="inventory" value="{$iteminfo['inventory']}">(开启规格后，库存必须为所有货品库存之和)
            </div>
          </div>
        </div>

        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">商品状态</div>
          <div class="am-u-sm-10">
            <div class="am-btn-group">
            <label class="am-radio-inline">  <input name="status" type="radio" value="1" 
            <if condition="$iteminfo['status'] eq 1 ">checked=1</if>  >出售中</label>
            <label class="am-radio-inline">  <input name="status" type="radio" value="2"  <if condition="$iteminfo['status'] eq 2 ">checked=1</if> >下架</label>
            </div>
          </div>
        </div>
        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">列表图片</div>
          <div class="am-u-sm-10">
           <div class="am-form-group">
		      <input type="file" id="doc-ipt-file-1" name='listimg'>
		      <p class="am-form-help">请选择要上传的文件...(像素要求300*380)</p>
          <div><if condition="$iteminfo['itemimg'] neq '' ">
          <img src="{:C('SITENAME')}{$iteminfo['itemimg']}">
          </if>
          </div>
   		 </div>
          </div>
        </div>


      </div>
	<!-- 商品基本信息end-->
		<!-- 商品详情-->
      <div class="am-tab-panel am-fade" id="tab2">
       <script type="text/plain" id="myEditor" style="width:1000px;height:540px;">
          {$detail}
       </script>
      </div>
	<!-- 商品详情end -->

    </div>
  </div>
</div>
<!-- content end -->

</div>


<footer>
  <hr>
  <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
</footer>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="{:C('SHOP_HOME_JS')}polyfill/rem.min.js"></script>
<script src="{:C('SHOP_HOME_JS')}polyfill/respond.min.js"></script>
<script src="{:C('SHOP_HOME_JS')}amazeui.legacy.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="{:C('SHOP_HOME_JS')}jquery.min.js"></script>
<script src="{:C('SHOP_HOME_JS')}amazeui.min.js"></script>
<!--<![endif]-->
<script src="{:C('SHOP_HOME_JS')}app.js"></script>
<script type="text/javascript" src="{:C('SHOP_HOME_JS')}third-party/jquery.min.js"></script>
<script type="text/javascript"charset="utf-8" src="{:C('SHOP_HOME_JS')}umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="{:C('SHOP_HOME_JS')}umeditor.min.js"></script>
<script type="text/javascript" src="{:C('SHOP_HOME_JS')}lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 // $('.tab2').tabs({noSwipe: 1});
});

 function reload(x){
 	var typeid=x;
    window.location.href="{:U(Item/addItem)}"+"?typeid="+typeid;
 }
</script>
<script type="text/javascript">
	function specval(x)
	{	
		var template="<option value='{1}'>{2}</option> ";
		var str_2 ="";
		//$('input[name='+x+ ']:checked').each(function()
		//$('.'+x).children().find(":checkbox").attr("checked",true).each(function()
		$('.'+x).children().find("input[type=checkbox]:checked").each(function()
		{
       		str =template;
       		str = str.replace("{2}",$(this).val() );
       		str = str.replace("{1}",$(this).attr('class'));
       		str_2+=str; 		  
		})
		if(str_2 ==''){
			alert('请先选择规格，才能添加货品');
			event.preventDefault();
		 	return false;

		}
		var sid=x.split("_")[1];
		var opt='<select name=prospec['+sid+'][]>'+str_2+'</select>';
		//var $ahref=$(this).attr('id');
		$('#'+x).replaceWith(opt);
		
		
    }
    function appendrow(){
    	/*var str='<tr class="row"><td><button class="am-btn am-btn-default am-btn-xs am-text-danger">
    	      <span class="am-icon-trash-o"></span> 删除</button></td>
    	      <td><a href="javascript:void" id= onclick=specval(this.id)> 请选择</a></td><td><a href="javascript:void"  onclick=specval(this.id) >请选择</a></td><td>Amaze UI
    	    </td></tr>';*/
    <?php  
         $str='var spids=\'<tr class="row"><td><button class="am-btn am-btn-default am-btn-xs am-text-danger"><span class="am-icon-trash-o"></span> 删除</button></td>';
    	  $tem='';
		 foreach($specs as $key=>$value)
		 {
 	         
 	      $tem.='<td><a href="javascript:void" id=spec_'.$key.' onclick=specval(this.id)>请选择</a></td>';
 	          
		 }
		 echo $str.$tem.'<td><input name=pprice[] type=text> </td><td> <input  name=pinventory[] type=text></td><td>Amaze UI </td></tr>;\'';

		?> 
		  $('#spectable').append(spids);
		 event.preventDefault();
		 return false;
    }
    
	//开启规格
	function openspec(x){
		
			$('.speccontain').toggle();
			event.preventDefault();
			return false;
	}
   	

</script>

<script type="text/javascript">
	    //实例化编辑器
    var um = UM.getEditor('myEditor');
    um.addListener('blur',function(){
        $('#focush2').html('编辑器失去焦点了')
    });
    um.addListener('focus',function(){
        $('#focush2').html('')
    });
    //按钮的操作
</script>
</body>
</html>
